﻿// Decompiled with JetBrains decompiler
// Type: MCM.Abstractions.Wrapper.SettingsPropertyDefinitionWrapper
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using HarmonyLib.BUTR.Extensions;
using MCM.Common;
using System;
using System.Reflection;

#nullable enable
namespace MCM.Abstractions.Wrapper
{
  public sealed class SettingsPropertyDefinitionWrapper : 
    ISettingsPropertyDefinition,
    IPropertyDefinitionBase,
    IPropertyDefinitionBool,
    IPropertyDefinitionDropdown,
    IPropertyDefinitionWithMinMax,
    IPropertyDefinitionWithEditableMinMax,
    IPropertyDefinitionWithFormat,
    IPropertyDefinitionWithCustomFormatter,
    IPropertyDefinitionWithId,
    IPropertyDefinitionText,
    IPropertyDefinitionGroupToggle,
    IPropertyGroupDefinition,
    IPropertyDefinitionButton
  {
    public IRef PropertyReference { get; }

    public SettingType SettingType { get; }

    public string DisplayName { get; }

    public int Order { get; }

    public bool RequireRestart { get; }

    public string HintText { get; }

    public Decimal MaxValue { get; }

    public Decimal MinValue { get; }

    public Decimal EditableMinValue { get; }

    public Decimal EditableMaxValue { get; }

    public int SelectedIndex { get; }

    public string ValueFormat { get; }

    public Type? CustomFormatter { get; }

    public string GroupName { get; }

    public int GroupOrder { get; }

    public string Id { get; }

    public bool IsToggle { get; }

    private char SubGroupDelimiter { get; }

    public string Content { get; }

    public SettingsPropertyDefinitionWrapper(object @object)
    {
      Type type = @object.GetType();
      PropertyInfo propertyInfo1 = AccessTools2.Property(type, nameof (SettingType));
      PropertyInfo propertyInfo2 = AccessTools2.Property(type, nameof (PropertyReference));
      PropertyInfo propertyInfo3 = AccessTools2.Property(type, nameof (DisplayName));
      PropertyInfo propertyInfo4 = AccessTools2.Property(type, nameof (HintText));
      PropertyInfo propertyInfo5 = AccessTools2.Property(type, nameof (Order));
      PropertyInfo propertyInfo6 = AccessTools2.Property(type, nameof (RequireRestart));
      PropertyInfo propertyInfo7 = AccessTools2.Property(type, nameof (GroupName));
      PropertyInfo propertyInfo8 = AccessTools2.Property(type, nameof (GroupOrder));
      PropertyInfo propertyInfo9 = AccessTools2.Property(type, nameof (MinValue));
      PropertyInfo propertyInfo10 = AccessTools2.Property(type, nameof (MaxValue));
      PropertyInfo propertyInfo11 = AccessTools2.Property(type, nameof (EditableMinValue));
      PropertyInfo propertyInfo12 = AccessTools2.Property(type, nameof (EditableMaxValue));
      PropertyInfo propertyInfo13 = AccessTools2.Property(type, nameof (SelectedIndex));
      PropertyInfo propertyInfo14 = AccessTools2.Property(type, nameof (ValueFormat));
      PropertyInfo propertyInfo15 = AccessTools2.Property(type, nameof (CustomFormatter));
      PropertyInfo propertyInfo16 = AccessTools2.Property(type, nameof (Id));
      PropertyInfo propertyInfo17 = AccessTools2.Property(type, nameof (IsToggle));
      PropertyInfo propertyInfo18 = AccessTools2.Property(type, nameof (SubGroupDelimiter));
      PropertyInfo propertyInfo19 = AccessTools2.Property(type, nameof (Content));
      object obj1 = propertyInfo1?.GetValue(@object);
      SettingType result;
      this.SettingType = obj1 != null ? (Enum.TryParse<SettingType>(obj1.ToString(), out result) ? result : SettingType.NONE) : SettingType.NONE;
      object object1 = propertyInfo2?.GetValue(@object);
      this.PropertyReference = object1 != null ? (object1 is IRef @ref ? @ref : (IRef) new RefWrapper(object1)) : (IRef) new ProxyRef<object>((Func<object>) (() => (object) null), (Action<object>) (_ => { }));
      object obj2 = propertyInfo3?.GetValue(@object);
      if (true)
        ;
      string str1 = obj2 is string str2 ? str2 : (obj2 != null ? obj2.ToString() : "ERROR");
      if (true)
        ;
      this.DisplayName = str1;
      object obj3 = propertyInfo4?.GetValue(@object);
      if (true)
        ;
      string str3 = obj3 is string str4 ? str4 : (obj3 != null ? obj3.ToString() : "ERROR");
      if (true)
        ;
      this.HintText = str3;
      int? nullable1 = propertyInfo5?.GetValue(@object) as int?;
      this.Order = nullable1.GetValueOrDefault(-1);
      bool? nullable2 = propertyInfo6?.GetValue(@object) as bool?;
      this.RequireRestart = nullable2.GetValueOrDefault(true);
      if (!(propertyInfo7?.GetValue(@object) is string empty1))
        empty1 = string.Empty;
      this.GroupName = empty1;
      nullable1 = propertyInfo8?.GetValue(@object) as int?;
      this.GroupOrder = nullable1.GetValueOrDefault(-1);
      object obj4 = propertyInfo9?.GetValue(@object);
      Decimal? nullable3;
      Decimal num1;
      if (obj4 == null)
      {
        num1 = 0M;
      }
      else
      {
        nullable3 = obj4 as Decimal?;
        num1 = nullable3.GetValueOrDefault();
      }
      this.MinValue = num1;
      object obj5 = propertyInfo10?.GetValue(@object);
      Decimal num2;
      if (obj5 == null)
      {
        num2 = 0M;
      }
      else
      {
        nullable3 = obj5 as Decimal?;
        num2 = nullable3.GetValueOrDefault();
      }
      this.MaxValue = num2;
      object obj6 = propertyInfo11?.GetValue(@object);
      Decimal num3;
      if (obj6 == null)
      {
        num3 = 0M;
      }
      else
      {
        nullable3 = obj6 as Decimal?;
        num3 = nullable3.GetValueOrDefault();
      }
      this.EditableMinValue = num3;
      object obj7 = propertyInfo12?.GetValue(@object);
      Decimal num4;
      if (obj7 == null)
      {
        num4 = 0M;
      }
      else
      {
        nullable3 = obj7 as Decimal?;
        num4 = nullable3.GetValueOrDefault();
      }
      this.EditableMaxValue = num4;
      nullable1 = propertyInfo13?.GetValue(@object) as int?;
      this.SelectedIndex = nullable1.GetValueOrDefault();
      if (!(propertyInfo14?.GetValue(@object) is string str6))
      {
        SettingType settingType = this.SettingType;
        if (true)
          ;
        string str5;
        switch (settingType)
        {
          case SettingType.Int:
            str5 = "0";
            break;
          case SettingType.Float:
            str5 = "0.00";
            break;
          default:
            str5 = string.Empty;
            break;
        }
        if (true)
          ;
        str6 = str5;
      }
      this.ValueFormat = str6;
      this.CustomFormatter = propertyInfo15?.GetValue(@object) as Type;
      if (!(propertyInfo16?.GetValue(@object) is string empty2))
        empty2 = string.Empty;
      this.Id = empty2;
      nullable2 = propertyInfo17?.GetValue(@object) as bool?;
      this.IsToggle = nullable2.GetValueOrDefault();
      this.SubGroupDelimiter = (propertyInfo18?.GetValue(@object) as char?).GetValueOrDefault('/');
      if (!(propertyInfo19?.GetValue(@object) is string empty3))
        empty3 = string.Empty;
      this.Content = empty3;
    }

    public SettingsPropertyDefinition Clone(bool keepRefs = true)
    {
      object obj = this.PropertyReference.Value;
      return new SettingsPropertyDefinition(SettingsUtils.GetPropertyDefinitionWrappers((object) this), (IPropertyGroupDefinition) new PropertyGroupDefinitionWrapper((object) this), keepRefs ? this.PropertyReference : (IRef) new StorageRef(obj), this.SubGroupDelimiter);
    }
  }
}
